using Gateway.Infrastructure.Provider.Operator;
using Gateway.IRepositories;

namespace Gateway.Domain.EFCore;

/// <summary>
/// 工作单元实现
/// </summary>
public class UnitOfWork : IUnitOfWork
{
    private readonly ShareCoreDbContext _context;
    private readonly IOperatorProvider _operatorProvider;
    /// <summary>
    /// 
    /// </summary>
    /// <param name="context"></param>
    /// <param name="operatorProvider"></param>
    public UnitOfWork(ShareCoreDbContext context,IOperatorProvider operatorProvider)
    {
        _context = context;
        _operatorProvider = operatorProvider;
    }

    public void Commit()
    {
        _context.SetOperator(_operatorProvider);
        _context.SaveChanges();
    }

    public async Task CommitAsync()
    {
        _context.SetOperator(_operatorProvider);
        await _context.SaveChangesAsync();
    }
}